package com.payment.ktb.activity.main4;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import com.android.volley.VolleyError;
import com.payment.ktb.Interface.HttpCallbackListener;
import com.payment.ktb.R;
import com.payment.ktb.activity.BaseActivity;
import com.payment.ktb.constants.Constants;
import com.payment.ktb.constants.HttpActions;
import com.payment.ktb.constants.HttpUrls;
import com.payment.ktb.utils.AlertDialogUtils;
import com.payment.ktb.utils.HttpUtils;
import com.payment.ktb.utils.ToastUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by syd on 2016/6/22.
 */
public class FeedbackActivity extends BaseActivity {

    @BindView(R.id.et_feedback_suggesstion)
    EditText et_feedback_suggesstion;
    @BindView(R.id.et_feedback_phone)
    EditText et_feedback_phone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_feedback);
        initTitle("意见反馈");
        ButterKnife.bind(this);
    }



    @OnClick(R.id.btn_feedback_submit)
    public void clickEvent(View view) {

        if (TextUtils.isEmpty(et_feedback_suggesstion.getText().toString())) {
            ToastUtils.showToast("内容不能为空");
        }else if (!TextUtils.isEmpty(et_feedback_phone.getText().toString()) && et_feedback_phone.getText().toString().length() != 11) {
            ToastUtils.showToast("请输入正确的手机号");
        } else {
            submit();
        }
    }



    private void submit() {

        progressDialogUtils.showProgress();

        //构造传输参数
        String content = et_feedback_suggesstion.getText().toString().trim();
        String contact = et_feedback_phone.getText().toString();

        //将参数放入map中
        HashMap<String, String> map = new HashMap<String,String>();
        map.put("content",content);
        map.put("contact",contact);

        //向服务器发送请求
        HttpUtils.HttpRequestByVollery(HttpUrls.URL, HttpActions.UserFeedbackState, map, mQueue, new HttpCallbackListener() {
            @Override
            public void onFinish(String response) {
                progressDialogUtils.dismissProgress();
                ToastUtils.showToast("您已成功提交！");
                startActivity(FeedbackResultActivity.class);
            }

            @Override
            public void onError(VolleyError volleyError) {
                progressDialogUtils.dismissProgress();
                AlertDialogUtils.showAlertDialog(mContext, volleyError.getMessage());
            }
        });
    }

}
